package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetListNoficationRequest;
import keeto.com.vn.bms.network.response.GetListNotificationResponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskGetListNotification extends AbstractTask {
	
	String Authkey;
	int pageLimit;
	int pageNumber;

	public TaskGetListNotification(BMSListener listener, IBMSCore core,String authKey, int pagelimit,int pagenumber) {
		super(listener, core);
		this.Authkey = authKey;
		this.pageLimit = pagelimit;
		this.pageNumber = pagenumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetListNoficationRequest request = new GetListNoficationRequest();
		request.setAuthkey(Authkey);
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetListNotificationResponse response = protocol.getListNotify(request);
		for (BMSListener mListener : listener){
			mListener.finishGetListNotification(response.getReturnCode(), response.getPageCount(), response.getArrayList());
		}
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mListener : listener){
			mListener.finishGetListNotification(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, IBMSConfig.UNINITIALIZED_INT, null);
		}
	}

}
